///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef __BUOLA_PYTHON_COBJECTBASE_H_
#define __BUOLA_PYTHON_COBJECTBASE_H_

#include <buola/python.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"

namespace buola { namespace python {

class CObjectBase
{
    struct SInternal
    {
        PyObject_HEAD
        CObjectBase *mBuola;
    };

public:
    CObjectBase(CType *pType);
    virtual ~CObjectBase();

    static int GetPythonObjectSize()    {   return sizeof(SInternal);   }
    static void PythonDeAlloc(SInternal *pSelf);
    static PyObject *PythonNew(PyTypeObject *pType,
                                PyObject *pArgs,PyObject *pKwds);
    static int PythonInit(SInternal *pSelf,PyObject *pArgs,
                                                    PyObject *pKwds);
    PyObject *GetPythonObject() {   return (PyObject*)mPython;      }

    void IncRef()               {   Py_XINCREF((PyObject*)mPython); }
    void DecRef()               {   Py_XDECREF((PyObject*)mPython); }

protected:
    static CObjectBase *GetBuolaPythonObject(PyObject*);

private:
    SInternal *mPython;

    friend class YObject;
};

/*namespace python*/ } /*namespace buola*/ }

#pragma GCC diagnostic pop

#endif
